package Geometry;

import java.util.ArrayList;
import java.util.List;

import android.graphics.Canvas;
import android.graphics.PointF;

public class Composite extends Picture {

	private List<Picture> components = new ArrayList<Picture>();
	
	public Composite() {
		super(-1,new PointF(0, 0));
	}
	
	public void addPicture(Picture pic) {
		components.add(pic);
	}
	
	public void insertPicture(Picture pic) {
		components.add(0, pic);
	}
	
	@Override
	public void draw(Canvas canv) {
		for(Picture p : components) {
			p.draw(canv);
		}
	}
	
	@Override
	public void move(float dx, float dy) {
		super.move(dx, dy);
		for(Picture p: components) {
			p.move(dx, dy);
		}
	}

	
	/**
	 * (x,y) is inside a composite if it is inside at least
	 * one of the components.
	 */
	@Override
	public boolean isInside(float x, float y) {
		// for each picture p in components
		for(Picture p: components) {
			//  for(int i = 0; i < p.size(); i++) {
		    // 			Picture p = components.get(i)
			if(p.isInside(x, y)) {
				return true;
			} else {
				// DO NOTHING!!!!!!!!!
			}
		}
		// if we get here, none of the components
		// contained the point (x,y)
		return false;
	}

}
